<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>消耗统计</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/zy_common.css"/>
    <link rel="stylesheet" href="../css/mobiscroll.jquery.min.css" />
    <link rel="stylesheet" href="../css/zy_base.css"/>
</head>
<body>
<div class="pos_f_t bgf5">
    <div class="mt20">
        <div class="flex_aj expend_tit bw pt20 col9 font15" id="choseDate">
            <img src="../img/icon5.png" alt="" style="width: .4rem;">
            <span class="col3 ml20">日期：</span><span class="mr20" id="timer">全部</span>
            <img src="../img/right.png" alt="" style="width: .14rem;">
        </div>
        <div class="h280 flex_column flex_aj bw">
            <p class="color1 font40" id="paperTotal"></p>
            <p class="col3 font14">商品消耗总量</p>
        </div>
    </div>
    <div class="mt20 font15 plr24 bw">
        <div class="flex_sb h100 bdb">
            <span class="col3">免费领取总量</span><span class="col9" id="freePaperTotal"></span>
        </div>
        <div class="flex_sb h100 bdb">
            <span class="col3">购买商品总量</span><span class="col9" id="payPaperTotal"></span>
        </div>
        <div class="flex_sb h100 bdb">
            <span class="col3">公众号关注量</span><span class="col9" id="gzhLikeTotal"></span>
        </div>
    </div>
    <div class="col6 font15 h100 lh100 plr24 bgf5">各设备消耗情况</div>
</div>
    <div class="expendBox" style="padding-top: 7.86rem;">
        <ul class="plr24 bw">
            <!--<li class="ptb30 col9 font13 bdb">-->
                <!--<p class="mb20 col3 font15">设备编号：4564654665465</p>-->
                <!--<p class="mb10">地址：广东省东莞市南城区高盛科技园</p>-->
                <!--<p class="mb10">免费领取总量：100</p>-->
                <!--<p class="mb10">购买商品总量：320</p>-->
                <!--<p class="mb10">公众号关注量：4213</p>-->
            <!--</li>-->
            <!--<li class="ptb30 col9 font13 bdb">-->
                <!--<p class="mb20 col3 font15">设备编号：4564654665465</p>-->
                <!--<p class="mb10">地址：广东省东莞市南城区高盛科技园</p>-->
                <!--<p class="mb10">免费领取总量：100</p>-->
                <!--<p class="mb10">购买商品总量：320</p>-->
                <!--<p class="mb10">公众号关注量：4213</p>-->
            <!--</li>-->
        </ul>
    </div>
</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script type="text/javascript" src="../js/mobiscroll.jquery.min.js"></script>
<script>

    $(function () {
        $('.expendBox').on('click','li',function () {
            saveLocalData('device_addr',$(this).data('addr'));
            saveLocalData('device_times',$(this).data('times'));
           location.href='./zy_device_details.html?macno='+$(this).data('macno');
        });
        //消耗统计详情
        getDeviceConsumeTotal();
        //列表
        dlc_request('/api/relation/getAgentDeviceRelationList',{agentId:getLocalData('fd_id')},function (res) {
            console.log(res);
            if(res.code==1){
                var str='';
                res.data.forEach(function (item,index) {
                   str+='<li class="ptb30 col9 font13 bdb" data-times="'+item.createTime+'" data-addr="'+item.addr+'" data-macno="'+item.deviceNo+'">'+
                            '<p class="mb20 col3 font15">设备编号：'+item.deviceNo+'</p>'+
                            '<p class="mb10">地址：'+item.addr+'</p>'+
                            '<p class="mb10">免费领取总量：'+item.freePaperTotal+'</p>'+
                            '<p class="mb10">购买商品总量：'+item.payPaperTotal+'</p>'+
                            '<p class="mb10">公众号关注量：'+item.gzhLikeTotal+'</p>'+
                        '</li>';
                });
                if(str){
                    $('.expendBox ul').html(str);
                }else{
                    $('.expendBox ul').removeClass('bw');
                    $('.expendBox ul').html(emptyTip('暂无数据'));
                }

            }
        });

        $('#choseDate').mobiscroll().date({
            theme: 'mobiscroll',
            timeFormat: 'yy-mm-dd',
            display: 'bottom',
            cancelText: '',
            setText: '',
            closeOnOverlay: false,
//            min:new Date(),
            max:new Date(),
            closeOnOverlayTap: false,
            showLabel: true,
            lang: 'zh',
            steps: {
//            minute: 30,
                zeroBased: true
            },
            onBeforeClose: function (event, inst) {
                var button=event.button;
                if (button !== 'cancel') {
                    console.log(event.valueText);
                    var choseDate=Number(new Date(event.valueText));
                    console.log(choseDate);
                    var _value=event.valueText.replace(/\//g,'-')
                    $('#timer').text(_value);
                    getDeviceConsumeTotal(_value);
                }
            },
//            onInit: function (event, inst) {
//                inst.setVal(new  Date(), true);
//            },
            headerText: function (valueText) {
                return "<div class='headerText'><a class='l' onclick='cancle1()'>取消</a>请选择日期<a class='r' onclick='confirm1();'>确定</a></div><div class='notnotice'></div>";
            }
        });

    })
    function cancle1() {
        $('#choseDate').mobiscroll('cancel');
    }

    function confirm1() {
        $('#choseDate').mobiscroll('hide');
    }

    function getDeviceConsumeTotal(createTime) {
        dlctipbox.loading('请稍后');
        var data = {
            agentId:getLocalData('fd_id')
        };
        if(createTime){
            data.createTime=createTime
        }
        dlc_request('/api/deviceConsumeTotal/getDeviceConsumeTotal',data,function (res) {
            dlctipbox.clear();
            console.log(res);
            if(res.code==1){
                $('#paperTotal').text(res.data.paperTotal);
                $('#gzhLikeTotal').text(res.data.gzhLikeTotal);
                $('#freePaperTotal').text(res.data.freePaperTotal);
                $('#payPaperTotal').text(res.data.payPaperTotal);
            }else if(res.code==0){
                $('#paperTotal').text(0);
                $('#gzhLikeTotal').text(0);
                $('#freePaperTotal').text(0);
                $('#payPaperTotal').text(0);
            }else{
                dlctipbox.show(res.msg);
            }
        })
    }
</script>
